SpatialData class
…
library(Rarr)
library(EBImage)
library(ggplot2)
library(jsonlite)
library(SpatialData)
library(SingleCellExperiment)
ImageArraypath <- file.path("extdata", "mibitof", "images", "point8_image")
zarr <- system.file(file.path(path, "0"), package = "SpatialData", mustWork = TRUE)
json <- system.file(file.path(path, ".zattrs"), package = "SpatialData", mustWork = TRUE)
za <- read_zarr_array(zarr)
md <- fromJSON(json)
(ia <- ImageArray(za, md))
## class: ImageArray
## axiis(cyx): 3 1024 1024
## |-time(0):
## |-space(2): y x
## |-channel(1): c
## channels: 0 1 2
readImagepath <- "extdata/mibitof/images/point8_image/0"
path <- system.file(path, package = "SpatialData")
(ia <- readImageArray(path))
## class: ImageArray
## axiis(cyx): 3 1024 1024
## |-time(0):
## |-space(2): y x
## |-channel(1): c
## channels: 0 1 2
SpatialDatapath <- "extdata/mibitof"
path <- system.file(path, package = "SpatialData")
(spd <- readSpatialData(path))
## class: SpatialData
## images(3): point16_image point23_image point8_image
## labels(3): point16_labels point23_labels point8_labels
## shapes(0):
## points(0):
elementNames(spd)
## [1] "images" "labels"
imageNames(spd)
## [1] "point16_image" "point23_image" "point8_image"
(img <- element(spd, "images", 1))
## class: ImageArray
## axiis(cyx): 3 1024 1024
## |-time(0):
## |-space(2): y x
## |-channel(1): c
## channels: 0 1 2
(lab <- element(spd, "labels", 1))
## class: ImageArray
## axiis(yx): 1024 1024
## |-time(0):
## |-space(2): y x
## |-channel(0):
## channels:
mtx <- as.array(aperm(img))
plot(Image(mtx/255, dim(mtx), "Color"))
mtx <- as.array(aperm(lab))
plot(Image(mtx, dim(mtx)))
(sce <- aggregateImage(spd))
## class: SingleCellExperiment
## dim: 3 1108
## metadata(0):
## assays(1): ''
## rownames: NULL
## rowData names(0):
## colnames(1108): 0 1 ... 1106 1107
## colData names(2): x y
## reducedDimNames(0):
## mainExpName: NULL
## altExpNames(0):
cd <- data.frame(colData(sce), z = assay(sce)[1, ])
ggplot(cd, aes(x, y, col = z)) + geom_point() +
scale_color_viridis_c() + scale_y_reverse()
# utility for image plotting with 'EBImage'
.plot <- \(i, c="Color") {
j <- as.array(aperm(i))
plot(Image(j/max(j), dim(j), c))
}
path <- file.path("extdata", "raccoon_scale")
path <- system.file(path, package = "SpatialData")
(spd <- readSpatialData(path))
## class: SpatialData
## images(1): raccoon
## labels(1): segmentation
## shapes(1): circles
## points(0):
(i <- image(spd))
## class: ImageArray
## axiis(cyx): 3 768 1024
## |-time(0):
## |-space(2): y x
## |-channel(1): c
## channels: 0 1 2
transformations(i)
## DataFrame with 1 row and 6 columns
## input.name output.name input.axes
## <character> <character> <list>
## 1 cyx global c:channel:NA,y:space:unit,x:space:unit
## output.axes type data
## <list> <character> <list>
## 1 c:channel:NA,y:space:unit,x:space:unit scale 1,1,2
# rotation
j <- SpatialData:::.rotate(i, 30)
par(mfrow=c(1,2)); .plot(i); .plot(j)
# scaling
j <- SpatialData:::.scale(i, c(1,1,2))
par(mfrow=c(1,2)); .plot(i); .plot(j)
sessionInfo()
## R version 4.3.0 (2023-04-21)
## Platform: aarch64-apple-darwin20 (64-bit)
## Running under: macOS Ventura 13.2.1
##
## Matrix products: default
## BLAS: /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/lib/libRblas.0.dylib
## LAPACK: /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/lib/libRlapack.dylib; LAPACK version 3.11.0
##
## locale:
## [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
##
## time zone: Europe/Berlin
## tzcode source: internal
##
## attached base packages:
## [1] stats4 stats graphics grDevices utils datasets methods
## [8] base
##
## other attached packages:
## [1] SingleCellExperiment_1.22.0 SummarizedExperiment_1.30.0
## [3] Biobase_2.60.0 GenomicRanges_1.52.0
## [5] GenomeInfoDb_1.36.0 IRanges_2.34.0
## [7] S4Vectors_0.37.4 BiocGenerics_0.45.3
## [9] MatrixGenerics_1.12.0 matrixStats_0.63.0
## [11] SpatialData_0.99 jsonlite_1.8.4
## [13] ggplot2_3.4.2 EBImage_4.42.0
## [15] Rarr_1.0.0 BiocStyle_2.28.0
##
## loaded via a namespace (and not attached):
## [1] tidyselect_1.2.0 viridisLite_0.4.1 farver_2.1.1
## [4] dplyr_1.1.2 arrow_11.0.0.3 R.utils_2.12.2
## [7] bitops_1.0-7 fastmap_1.1.1 RCurl_1.98-1.12
## [10] digest_0.6.31 lifecycle_1.0.3 paws.storage_0.2.0
## [13] magrittr_2.0.3 compiler_4.3.0 rlang_1.1.0
## [16] sass_0.4.5 tools_4.3.0 utf8_1.2.3
## [19] yaml_2.3.7 knitr_1.42 labeling_0.4.2
## [22] S4Arrays_1.0.0 htmlwidgets_1.6.2 bit_4.0.5
## [25] curl_5.0.0 DelayedArray_0.25.0 abind_1.4-5
## [28] withr_2.5.0 purrr_1.0.1 R.oo_1.25.0
## [31] grid_4.3.0 fansi_1.0.4 colorspace_2.1-0
## [34] scales_1.2.1 cli_3.6.1 rmarkdown_2.21
## [37] crayon_1.5.2 generics_0.1.3 rstudioapi_0.14
## [40] httr_1.4.5 cachem_1.0.7 stringr_1.5.0
## [43] zlibbioc_1.46.0 assertthat_0.2.1 BiocManager_1.30.20
## [46] XVector_0.40.0 tiff_0.1-11 vctrs_0.6.2
## [49] Matrix_1.5-4 bookdown_0.33 fftwtools_0.9-11
## [52] bit64_4.0.5 magick_2.7.4 jpeg_0.1-10
## [55] locfit_1.5-9.7 jquerylib_0.1.4 glue_1.6.2
## [58] stringi_1.7.12 gtable_0.3.3 munsell_0.5.0
## [61] tibble_3.2.1 pillar_1.9.0 htmltools_0.5.5
## [64] GenomeInfoDbData_1.2.10 R6_2.5.1 evaluate_0.20
## [67] lattice_0.21-8 highr_0.10 R.methodsS3_1.8.2
## [70] png_0.1-8 paws.common_0.5.6 bslib_0.4.2
## [73] Rcpp_1.0.10 xfun_0.39 pkgconfig_2.0.3